<?php

/**
 *    默认Rewrite引擎
 *
 *    @author    Garbin
 *    @usage    none
 */

/*

##### Rewrite Rule #####

RewriteEngine On

#商品详情
RewriteRule ^goods/([0-9]+).html$ index.php?app=goods&id=$1 [L]
RewriteRule ^goods/([0-9]+)/([^/]+).html$ index.php?app=goods&id=$1&act=$2 [L]
RewriteRule ^goods/([0-9]+)/([^/]+)/page_([^/]+).html$ index.php?app=goods&id=$1&act=$2&page=$3 [L]
RewriteRule ^groupbuy/([0-9]+).html$ index.php?app=groupbuy&id=$1 [L]

#分类
RewriteRule ^category/goods.html$ index.php?app=category [L]
RewriteRule ^category/(.*).html$ index.php?app=category&act=$1 [L]

#品牌
RewriteRule ^brand.html$ index.php?app=brand [L]

#文章
RewriteRule ^article/help.html$ index.php?app=article&code=help [L]
RewriteRule ^article/category/([0-9]+).html$ index.php?app=article&cate_id=$1 [L]
RewriteRule ^article/category/([0-9]+)/page_([^/]+).html$ index.php?app=article&cate_id=$1&page=$2 [L]
RewriteRule ^article/([0-9]+).html$ index.php?app=article&act=view&article_id=$1 [L]
RewriteRule ^article/keyword/([^/]+).html$ index.php?app=article&help_keyword=$1 [L]
RewriteRule ^article/keyword/([^/]+)/page_([^/]+).html$ index.php?app=article&help_keyword=$1&page=$2 [L]

#店铺页面
RewriteRule ^store/([0-9]+).html$ index.php?app=store&id=$1 [L]
RewriteRule ^store/article/([0-9]+).html$ index.php?app=store&act=article&id=$1 [L]
RewriteRule ^store/([0-9]+)/credit.html$ index.php?app=store&id=$1&act=credit [L]
RewriteRule ^store/([0-9]+)/credit/page_([^/]+).html$ index.php?app=store&id=$1&act=credit&page=$2 [L]
RewriteRule ^store/([0-9]+)/credit/([0-9]+).html$ index.php?app=store&id=$1&act=credit&eval=$2 [L]
RewriteRule ^store/([0-9]+)/credit/([0-9]+)/page_([^/]+).html$ index.php?app=store&id=$1&act=credit&eval=$2&page=$3 [L]
RewriteRule ^store/([0-9]+)/goods.html$ index.php?app=store&id=$1&act=search [L]
RewriteRule ^store/([0-9]+)/goods/page_([^/]+).html$ index.php?app=store&id=$1&act=search&page=$2 [L]
RewriteRule ^store/([0-9]+)/category/([0-9]+).html$ index.php?app=store&id=$1&act=search&cate_id=$2 [L]
RewriteRule ^store/([0-9]+)/category/([0-9]+)/page_([^/]+).html$ index.php?app=store&id=$1&act=search&cate_id=$2&page=$3 [L]
RewriteRule ^store/([0-9]+)/groupbuy.html$ index.php?app=store&id=$1&act=groupbuy [L]
RewriteRule ^store/([0-9]+)/groupbuy/page_([^/]+).html$ index.php?app=store&id=$1&act=groupbuy&page=$2 [L]
RewriteRule ^store/([0-9]+)/about.html$ index.php?app=store&id=$1&act=about [L]

#搜索页面
RewriteRule ^search/is_hot.html$ index.php?app=search&is_hot=1 [L]
RewriteRule ^search/is_hot/page_([^/]+).html$ index.php?app=search&is_hot=1&page=$1 [L]
RewriteRule ^search/cate_id/([0-9]+).html$ index.php?app=search&cate_id=$1 [L]
RewriteRule ^search/cate_id/([0-9]+)/page_([^/]+).html$ index.php?app=search&cate_id=$1&page=$2 [L]

#特色页面
RewriteRule ^tese.html$ index.php?app=tese [L]
RewriteRule ^tese/page_([^/]+).html$ index.php?app=tese&page=$1 [L]
RewriteRule ^tese/cate_id/([0-9]+).html$ index.php?app=tese&cate_id=$1 [L]
RewriteRule ^tese/cate_id/([0-9]+)/page_([^/]+).html$ index.php?app=tese&cate_id=$1&page=$2 [L]
 
#场景分类页面
RewriteRule ^place_category/cate_id/([0-9]+).html$ index.php?app=place_category&cate_id=$1 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/page_([^/]+).html$ index.php?app=place_category&cate_id=$1&page=$2 [L]

RewriteRule ^place_category/cate_id/([0-9]+)/order/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&order=$2 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/price/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&price=$2 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/start_stock/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&start_stock=$2 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/order/([\w|\-]+)/price/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&order=$2&price=$3 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/order/([\w|\-]+)/start_stock/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&order=$2&start_stock=$3 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/price/([\w|\-]+)/start_stock/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&price=$2&start_stock=$3 [L]
RewriteRule ^place_category/cate_id/([0-9]+)/order/([\w|\-]+)/price/([\w|\-]+)/start_stock/([\w|\-]+).html$ index.php?app=place_category&cate_id=$1&order=$2&price=$3&start_stock=$4 [L]

#专题页面
RewriteRule ^zt_([^/]+).html$ index.php?app=static&id=$1 [L]
RewriteRule ^lianwuzhi([^/]+).html$ index.php?app=static&act=lianwuzhi&id=$1 [L]
RewriteRule ^shiyouji([^/]+).html$ index.php?app=static&act=shiyouji&id=$1 [L]

#消费保障页面
RewriteRule ^security.html$ index.php?app=baozhang [L]

*/

class DefaultRewrite extends BaseRewrite
{
    /* Rewrite规则地图，记录参数对应的rule名称 */
    var $_rewrite_maps  = array(
        /* '{app名称}_{参数列表，按升序排序，"_"连接}' => '重写规则名称', */

        /* 店铺首页 */
        'store_id'  => 'store_index',

        /* 商品详情 */
        'goods_id'  => 'goods_detail',
        'groupbuy_id'   => 'groupbuy_detail',

        /* 商品分类 */
        'category'  => 'goods_cate',

        /* 品牌列表 */
        'brand'     => 'brand_list',

        /* 店铺分类 */
        'category_act' => 'store_cate',

        /* 文章详情 */
        'article_code' => 'article_help',//帮助中心
        'article_cate_id' => 'article_category',//文章分类
        'article_act_id' => 'article_detail',
        'article_act_article_id' => 'article_detail',
        'article_help_keyword' => 'article_keyword',
        'article_cate_id_page' => 'article_category_page',//文章分类分页
        'article_help_keyword_page' => 'article_keyword_page',//搜索文章分页

        /* 店铺文章 */
        'store_act_id'  => REWRITE_RULE_FN,
        'store_act_id_page' => REWRITE_RULE_FN,
        'store_act_eval_id' => 'store_credit_eval',
        'store_act_eval_id_page'    => 'store_credit_eval_page',
        'store_act_cate_id_id'  => 'store_goodscate',
        'store_act_cate_id_id_page' => 'store_goodscate_page',
        'goods_act_id'      => 'goods_extra_info',
        'goods_act_id_page' => 'goods_extra_info_page',
        
        /* 热门商品 */
        'search_is_hot' => 'search_hot',
        'search_is_hot_page' => 'search_hot_page',

        /* 搜索分类 */
        'search_cate_id' => 'search_category',
        'search_cate_id_page' => 'search_category_page',

        /* 特色页面 */
        'tese' => 'tese',
        'tese_page' => 'tese_page',
        'tese_cate_id' => 'tese_category',
        'tese_cate_id_page' => 'tese_category_page',
        
        //场景分类页面
        'place_category_cate_id' => 'place_category_category',
        'place_category_cate_id_page' => 'place_category_category_page',

        //专题页面
        'static_id' => 'static_category',
        'static_act_id' =>  REWRITE_RULE_FN,

        //消费保障页面
        'baozhang' => 'baozhang',

    );

    /* Rewrite rules，记录各规则信息 */
    var $_rewrite_rules = array(
        'store_index'   => array(
            'rewrite'   => 'store/%id%.html',
        ),
        'goods_detail'  => array(
            'rewrite'   => 'goods/%id%.html',
        ),
        'goods_cate'    => array(
            'rewrite'   => 'category/goods.html',
        ),
        'brand_list'    => array(
            'rewrite'   => 'brand',
        ),
        'store_cate'    => array(
            'rewrite'   => 'category/%act%.html',
        ),
        'article_help'    => array(
            'rewrite'   => 'article/help.html',
        ),
        'article_keyword'    => array(
            'rewrite'   => 'article/keyword/%help_keyword%.html',
        ),
		'article_keyword_page'    => array(
            'rewrite'   => 'article/keyword/%help_keyword%/page_%page%.html',
        ),
        'article_category'    => array(
            'rewrite'   => 'article/category/%cate_id%.html',
        ),
        'article_category_page'    => array(
            'rewrite'   => 'article/category/%cate_id%/page_%page%.html',
        ),		
        'article_detail'    => array(
            'rewrite'   => 'article/%article_id%.html',
        ),
        'store_article' => array(
            'rewrite'   => 'store/article/%id%.html',
        ),
        'store_credit'  => array(
            'rewrite'   => 'store/%id%/credit.html',
        ),
        'store_credit_page'  => array(
            'rewrite'   => 'store/%id%/credit/page_%page%.html',
        ),
        'store_credit_eval'  => array(
            'rewrite'   => 'store/%id%/credit/%eval%.html',
        ),
        'store_credit_eval_page'    => array(
            'rewrite'   => 'store/%id%/credit/%eval%/page_%page%.html',
        ),
        'store_goodslist'   => array(
            'rewrite'   => 'store/%id%/goods.html',
        ),
        'store_goodslist_page'   => array(
            'rewrite'   => 'store/%id%/goods/page_%page%.html',
        ),
        'store_goodscate'   => array(
            'rewrite'   => 'store/%id%/category/%cate_id%.html',
        ),
        'store_goodscate_page'   => array(
            'rewrite'   => 'store/%id%/category/%cate_id%/page_%page%.html',
        ),
        'goods_extra_info' => array(
            'rewrite'   => 'goods/%id%/%act%.html',
        ),
        'goods_extra_info_page' => array(
            'rewrite'   => 'goods/%id%/%act%/page_%page%.html',
        ),
        'groupbuy_detail'   =>  array(
            'rewrite'   => 'groupbuy/%id%.html',
        ),
        'store_groupbuy'   =>  array(
            'rewrite'   => 'store/%id%/groupbuy.html',
        ),
        'store_groupbuy_page'   =>  array(
            'rewrite'   => 'store/%id%/groupbuy/page_%page%.html',
        ),
        'store_about'   =>  array(
            'rewrite'   => 'store/%id%/about.html',
        ),
        'search_hot'   =>  array(
            'rewrite'   => 'search/is_hot.html',
        ),
        'search_hot_page'   =>  array(
            'rewrite'   => 'search/is_hot/page_%page%.html',
        ),
        'search_category'   =>  array(
            'rewrite'   => 'search/cate_id/%cate_id%.html',
        ),
        'search_category_page'   =>  array(
            'rewrite'   => 'search/cate_id/%cate_id%/page_%page%.html',
        ),
        'tese'   =>  array(
            'rewrite'   => 'tese.html',
        ),
        'tese_page'   =>  array(
            'rewrite'   => 'tese/page_%page%.html',
        ),
        'tese_category'   =>  array(
            'rewrite'   => 'tese/cate_id/%cate_id%.html',
        ),
        'tese_category_page'   =>  array(
            'rewrite'   => 'tese/cate_id/%cate_id%/page_%page%.html',
        ),
        'place_category_category'   =>  array(
            'rewrite'   => 'place_category/cate_id/%cate_id%.html',
        ),
        'place_category_category_page'   =>  array(
            'rewrite'   => 'place_category/cate_id/%cate_id%/page_%page%.html',
        ),
        'static_category'   =>  array(
            'rewrite'   => 'zt_%id%.html',
        ),
        'static_lianwuzhi'   =>  array(
            'rewrite'   => 'lianwuzhi%id%.html',
        ),
        'static_shiyouji'   =>  array(
            'rewrite'   => 'shiyouji%id%.html',
        ),
        'baozhang'   =>  array(
            'rewrite'   => 'security.html',
        ),
    );


    function rule_store_act_id($params)
    {
        $rule_name = '';
        switch ($params['act'])
        {
            case 'article':
                $rule_name = 'store_article';
            break;
            case 'credit':
                $rule_name = 'store_credit';
            break;
            case 'search':
                $rule_name = 'store_goodslist';
            break;
            case 'groupbuy':
                $rule_name = 'store_groupbuy';
            break;
            case 'about':
                $rule_name = 'store_about';
            break;
        }
        return $rule_name;
    }

    function rule_static_act_id($params)
    {
        $rule_name = '';
        switch ($params['act'])
        {
            case 'lianwuzhi':
                $rule_name = 'static_lianwuzhi';
                break;
            case 'shiyouji':
                $rule_name = 'static_shiyouji';
                break;
        }
        return $rule_name;
    }

    function rule_store_act_id_page($params)
    {
        $rule_name = '';
        switch ($params['act'])
        {
            case 'credit':
                $rule_name = 'store_credit_page';
            break;
            case 'search':
                $rule_name = 'store_goodslist_page';
            break;
            case 'groupbuy':
                $rule_name = 'store_groupbuy_page';
            break;
        }

        return $rule_name;
    }
}

?>
